package com.yby.mall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.yby.common.utils.PageUtils;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yby.mall.product.entity.AttrGroupEntity;
import com.yby.mall.product.service.AttrGroupService;
import com.yby.common.utils.R;



/**
 * 属性分组
 *
 * @author yangbingying
 * @email 2771355658@qq.com
 * @date 2021-07-09 20:49:20
 */
@Api(value = "", tags = "属性分组")
@RestController
@RequestMapping("product/attrgroup")
public class AttrGroupController {
    @Autowired
    private AttrGroupService attrGroupService;

    /**
     * 列表
     */
    @GetMapping("/{attrGroupId}/noattr/relation")
    public R list(@PathVariable Long attrGroupId,Integer page,Integer limit,String key){
        return  attrGroupService.queryPageNoAttr(attrGroupId,page,limit,key);
    }


    @GetMapping("/{catalogId}/withattr")
    public R withAttrList(@PathVariable Long catalogId){
        return  attrGroupService.withAttrList(catalogId);
    }

    @GetMapping("/list/{catId}")
    public R list(@PathVariable Integer catId,Integer page,Integer limit,String key){
        return  attrGroupService.queryPage(catId,page,limit,key);
    }


    @GetMapping("/{attrGroupId}/attr/relation")
    public R attrRelationList(@PathVariable Long attrGroupId){
        return  attrGroupService.attrRelationList(attrGroupId);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{attrGroupId}")
    public R info(@PathVariable("attrGroupId") Long attrGroupId){
        return attrGroupService.getInfo(attrGroupId);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody AttrGroupEntity attrGroup){
		attrGroupService.save(attrGroup);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody AttrGroupEntity attrGroup){
		attrGroupService.updateById(attrGroup);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] attrGroupIds){
		attrGroupService.removeByIds(Arrays.asList(attrGroupIds));
        return R.ok();
    }

    /**
     * 属性分组关联移除
     */
    @PostMapping("/attr/relation/delete")
    public R deleteAttrRelation(@RequestBody List<Map<String,Object>> list){
        return attrGroupService.deleteAttrRelation(list);
    }

    /**
     * 属性分组关联移除
     */
    @PostMapping("/attr/relation")
    public R insertAttrRelation(@RequestBody List<Map<String,Object>> list){
        return attrGroupService.insertAttrRelation(list);
    }


}
